package com.streambolics.worseminton.servlet;

import javax.servlet.http.HttpServletRequest;

import com.streambolics.std.HtmlBuilder;
import com.streambolics.worseminton.data.Invitation;

public class InvitationCommentHandler extends InvitationHandler
{
    @Override
    protected void formatBodyAsSimpleDesktopHtml (HtmlBuilder aBuilder, Invitation aResponseObject) throws Exception
    {
        Snippets.generateInvitationComment (aBuilder, aResponseObject, "/go/InvitationComment", "Comment");
    }

    @Override
    protected Invitation generateResponseObject (HttpServletRequest aRequest) throws Exception
    {
        Invitation i = super.generateResponseObject (aRequest);
        String comment = getParameter ("COMMENT");
        String privatecomment = getParameter ("PRIVATECOMMENT");

        if (comment == null && privatecomment == null)
        {
            warnAbout (new Exception ("Please enter a comment"));
        }
        else if (requireWritePermission (i))
        {
            updateComments (i);
        }
        return i;
    }

    @Override
    protected String getRedirect (Invitation aResponseObject)
    {
        return aResponseObject.getIdUrl ("/go/Invitation");
    }

}
